//package com.example.service.impl;/**
// * @author wangXiao
// */
//
//import com.example.entity.SysUser;
//import com.example.entity.base.ResponseData;
//import com.example.entity.dto.LoginVo;
//import com.example.mapper.UserMapper;
//import com.example.security.bean.CustomUser;
//import com.example.service.SysUserService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Objects;
//
///**
// * @Description: TODO
// * @Author wangXiao
// * @Date 2024/10/10
// **/
//@Service
//@Slf4j
//public class SysUserServiceImpl implements SysUserService {
//
//    @Resource
//    UserMapper userMapper;
//
//
//    /**
//     * 通过AuthenticationManager的authenticate方法来进行用户认证,
//     */
//    @Resource
//    private AuthenticationManager authenticationManager;
//
//
//    @Override
//    public SysUser queryByUsername(String username) {
//        return userMapper.selectUserByName(username);
//    }
//
//    @Override
//    public ResponseData<Map<String, Object>> login(LoginVo loginVo) {
//        // 将表单数据封装到 UsernamePasswordAuthenticationToken
//        UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(loginVo.getUsername(), loginVo.getPassword());
//        // authenticate方法会调用loadUserByUsername
//        Authentication authenticate = authenticationManager.authenticate(usernamePasswordAuthenticationToken);
//        if(Objects.isNull(authenticate)){
//            throw new RuntimeException("用户名或密码错误");
//        }
//        // 校验成功，强转对象
//        CustomUser customUser = (CustomUser) authenticate.getPrincipal();
//        SysUser sysUser = customUser.getSysUser();
//        // 校验通过返回token
//        String token = sysUser.getId()+sysUser.getName()+"123";
//        Map<String, Object> map = new HashMap<>();
//        map.put("token",token);
//        return ResponseData.ok(map);
//
//    }
//}
